package com.trans.defualtExcutor;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.trans.model.Model1;

public class ParseJson {

	public Model1 init(String file) {
		Long time1 = System.currentTimeMillis();
		//Gson转换
		GsonBuilder builder = new GsonBuilder();
		//		builder.registerTypeAdapter(Long.class, new BadLongDeserializer());
		//		builder.registerTypeAdapter(Integer.class, new BadIntegerDeserializer());
		//		builder.registerTypeAdapter(Date.class, new BadDateDeserializer());
		//设计日期格式
		builder.setDateFormat("yyyy-MM-dd HH:mm:ss");
		Gson gson = builder.create();
		//		Gson gson =new Gson();
		Model1 orderList = gson.fromJson(file, new TypeToken<Model1>() {
		}.getType());
		Long time2 = System.currentTimeMillis();
		System.out.println("=================Gson转换json成功，耗时为:" + (time2 - time1) + "ms==================");
		//fastJson转换
		//		Object obj = new Date();
		//		String json = JSON.toJSONStringWithDateFormat(obj, "yyyy-MM-dd HH:mm:ss.SSS");
		JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
		//		JSON.toJSONString(obj, SerializerFeature.WriteDateUseDateFormat);
		Model1 result = JSON.parseObject(file, Model1.class);

		Long time3 = System.currentTimeMillis();
		System.out.println("=================fastJson转换json成功，耗时为:" + (time3 - time2) + "ms=================");
		return result;
	}

}
